/**
* ...
* @author Default
* @version 0.1
*/

package  
{
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	import flash.utils.*;
	
	
	public class Main extends MovieClip
	{
		
		public var scene:Scene3D;
		private var osc:Number = 0;
		private var oscInc:Number = Math.PI / 180;
		
		private var texte:TextField;
		private var tf:TextFormat;
		public function Main() 
		{
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			
			scene = new Scene3D();
			
			addChild( scene );
			
			addEventListener(Event.ENTER_FRAME, update );
			
			
			texte = new TextField()
			addChild( texte );
			tf = new TextFormat( 'Verndana', 10, 0xFFFFFF );
			texte.setTextFormat( tf );
			
			stage.addEventListener( Event.RESIZE, onResizeHandler );
			onResizeHandler();
			
		}
		
		public function onResizeHandler( e:Event = null ):void
		{
			
			Scene3D.camera.viewport = new Rectangle( 0,0, stage.stageWidth, stage.stageHeight );
			
			Scene3D.camera.x = stage.stageWidth/2;
			Scene3D.camera.y = stage.stageHeight/2;
			
		}
		
		public function update( e:Event ):void
		{
			
			var t:int = getTimer();
			
			
			scene.render();
			
			
			texte.text = ( getTimer() - t ).toString() + '\n';
			texte.appendText( scene.visibleTriangles.toString() + ' tris\n' );
			texte.appendText( Scene3D.focalLength.toString() + ' fl\n\n' );
			
			texte.appendText( Scene3D.camera.x + ' cx \n' );
			texte.appendText( Scene3D.camera.y + ' cy \n' );
			texte.appendText( Scene3D.camera.z + ' cz \n' );
			
			
			texte.setTextFormat( tf );
			
		}
		
	}
}
